<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="/opebs/date/css/bootstrap-datetimepicker.css">

<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="/opebs/date/js/bootstrap-datetimepicker.js"></script>

<link href="/lib/ueditor/themes/css/umeditor.css" type="text/css" rel="stylesheet">
<script type="text/javascript" charset="utf-8" src="/lib/ueditor/js/umeditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/lib/ueditor/js/editor_api.js"></script>
<script type="text/javascript" src="/lib/ueditor/lang/zh-cn/zh-cn.js"></script>

<link href="/bootstrap-fileinput-master/css/fileinput.css" media="all" rel="stylesheet" type="text/css"/>
<script src="/bootstrap-fileinput-master/js/fileinput.js" type="text/javascript"></script>
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>

<body>
<form class="form-horizontal" id="form-finance-add" style="margin-top: 1%">


    <div class="form-group has-success">
        <label class="col-sm-2 control-label" for="inputSuccess">时间</label>
        <div class="col-sm-9">
                <input class="form-control" id="assignTime" size="14" type="text" value="<#if finance??>${finance.assignTime!}</#if>" >
            <input type="hidden" id="assignTime" value="" />
        </div>
    </div>

    <div class="form-group has-success">
        <label class="col-sm-2 control-label" for="inputSuccess">收入</label>
        <div class="col-sm-9">
            <input class="form-control" id="assignMoney" type="text"  value="<#if finance??>${finance.assignMoney!}</#if>">
        </div>
    </div>

    <div class="form-group has-success">
        <label class="col-sm-2 control-label" for="inputSuccess">支出</label>
        <div class="col-sm-9">
            <input class="form-control" id="incomeMoney" type="text"  value="<#if finance??>${finance.incomeMoney!}</#if>">
        </div>
    </div>

    <div class="form-group has-success">
        <label class="col-sm-2 control-label" for="inputSuccess">
            说明
        </label>
        <div class="col-sm-9">
            <input id="assignShow" class="form-control" size="14" type="text" value="<#if finance??>${finance.assignShow!}</#if>" >
            <#--<script type="text/plain" id="myEditor" style="width:100%;height:150px;"><#if finance??>${finance.assignShow!}</#if></script>-->
        </div>
    </div>


    <div class="form-group  has-success">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="button" id="save" class="btn btn-default">保存</button>
        </div>
    </div>
</form>
</body>
<script type="text/javascript">
    $('.form_date').datetimepicker({
        language:  'fr',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0
    });
    var um = UM.getEditor('myEditor',{
        //这里可以选择自己需要的工具按钮名称,此处仅选择如下七个
        toolbar:['fullscreen source undo redo bold italic underline'],
        //focus时自动清空初始化时的内容
        autoClearinitialContent:false,
        //关闭字数统计
        wordCount:false,
        //关闭elementPath
        elementPathEnabled:false,
        //默认的编辑区域高度
        initialFrameHeight:300
        //更多其他参数，请参考umeditor.config.js中的配置项
    });
</script>
<script>
    var id = ${id};
    var localId = ${localId};
    $("#input-b2").fileinput({
        language : 'zh',//设置文中文
        uploadUrl : "/upload-json/TH/"+id,//图片上传的url，我这里对应的是后台struts配置好的的action方法
        showCaption : true,//显示标题
        showRemove : true, //显示移除按钮
        uploadAsync : true,//默认异步上传
        textEncoding : "UTF-8",//文本编码
    });
    $("#input-b2").on('fileuploaded', function(event, data, previewId, index) {//异步上传成功结果处理
    });
    $("#input-b2").on('fileerror', function(event, data, msg) {//异步上传失败结果处理
    });
    $('#save').click(function () {
        var assignMoney = $('#assignMoney').val();
        var assignTime = $('#assignTime').val();
        var content = $('#assignShow').val();
        var incomeMoney = $('#incomeMoney').val();
        var moneyType = '';
        if(typeof assignMoney != "undefined" && assignMoney != null && assignMoney != ""){
            moneyType = '0';
        }else if(typeof incomeMoney != "undefined" && incomeMoney != null && incomeMoney != ""){
            moneyType = '1';
        }
        // var content = um.getPlainTxt();
        if((assignMoney == null || assignMoney == '') && (incomeMoney == null || incomeMoney == '')
            || (assignMoney != null && assignMoney!='' && incomeMoney!=null && incomeMoney !='')){
            layer.msg("请选填收入或支出！")
        }else {
            $.ajax({
                url: "/finance-ins-upd-del/" + localId,
                data: {
                    assignMoney: assignMoney,
                    assignTime: assignTime,
                    assignShow: content,
                    proID: id,
                    moneyType: moneyType,
                    incomeMoney: incomeMoney
                },
                async: false,
                success: function (data) {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            })
        }
    })
</script>
